package com.uenpay.im;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.TextView;

import com.qyx.android.weight.link.QyxLinkify;

import java.util.regex.Pattern;

/**
 * @Author: SL
 * @Date: 2017/4/13 15:38
 * @CopyRight: http://www.qiyunxin.com
 * @Parameter: TODO
 * @Function: TODO
 */
public class LinkDefs {
    public static final String MENTIONS_SCHEMA = IMApplication.getInstance().getAppPackageName() + "://url";
    public static final String PARAM_UID = "url";


    public static void extractUrl2Link(TextView v) {
        Pattern wikiWordMatcher = Pattern
                .compile("(?i)(((http\\:\\/\\/)|(https\\:\\/\\/)|(www\\.))[a-zA-Z0-9\\./?%&amp;=\\#_\\+\\-\\:]+)");
        String mentionsScheme = String.format("%s/?%s=", LinkDefs.MENTIONS_SCHEMA,
                LinkDefs.PARAM_UID);
        v.setLinkTextColor(IMApplication.getAppContext().getResources().getColor(
                com.uenpay.im.R.color.CLR007aff));
        QyxLinkify.addLinks(v, wikiWordMatcher, mentionsScheme);
    }

    public static View.OnTouchListener mOnTouchListener = new View.OnTouchListener() {
        long mLastActionDownTime = -1;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_UP
                    || action == MotionEvent.ACTION_DOWN) {
                if (action == MotionEvent.ACTION_UP) {
                    long actionUpTime = System.currentTimeMillis();
                    if (actionUpTime - mLastActionDownTime > ViewConfiguration
                            .getLongPressTimeout()) {
                        QyxLinkify.mIsLongClick = true;
                    }
                } else if (action == MotionEvent.ACTION_DOWN) {
                    QyxLinkify.mIsLongClick = false;
                    mLastActionDownTime = System.currentTimeMillis();
                }
            }
            return false;
        }
    };

}
